package com.hlz.fastnote

import android.content.Context
import android.view.WindowManager
import android.widget.EditText
import android.widget.TextView

class MyDialog(context: Context?) : BaseCenterDialog(context) {
    override val layout: Int
        protected get() = R.layout.dialog_my

    override fun initView() {

        val etTitle = findViewById<EditText>(R.id.etTitle)
        val tvCancel = findViewById<TextView>(R.id.tvCancel)
        val tvSure = findViewById<TextView>(R.id.tvSure)


        tvCancel.setOnClickListener {
            cancel()
        }

        tvSure.setOnClickListener {
            val title = etTitle.text.toString().trim()
            if (title.isNullOrEmpty()) {
                ToastUtil.showToast("请输入标题")
                return@setOnClickListener
            }
            listener?.save(title)
            cancel()
        }
    }

    override fun show() {
        super.show()
        listener?.show()

    }

    override fun dismiss() {
        super.dismiss()
        listener?.dismiss()
    }

    var listener: OnDialogListener? = null
    fun setOnDialogListener(listener: OnDialogListener) {
        this.listener = listener
    }

    override fun setHeight(): Int {
        return WindowManager.LayoutParams.WRAP_CONTENT
    }

    override fun setWidth(): Int {
        return (super.setWidth()*0.8f).toInt()
    }

    interface OnDialogListener {
        fun save(text: String)
        fun dismiss()
        fun show()
    }
}